﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Aoxuelf.MDSTool.ViewModel;
using Aoxuelf.MDSTool.Model;

namespace Aoxuelf.MDSTool.UI
{
    /// <summary>
    /// InsertBLLUpdateForm.xaml 的交互逻辑
    /// </summary>
    public partial class InsertBLLUpdateForm : Window
    {
        public InsertBLLUpdateForm()
        {
            InitializeComponent();
        }

        public InsertBLLUpdateViewModel ViewModel { get; set; }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = ViewModel;
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.ViewModel.MethodName.Length == 0)
            {
                MessageBox.Show("方法名不能为空");
                txtMethodName.Focus();
                return;
            }

            try
            {
                BLLUpdateMethodInfo info = new BLLUpdateMethodInfo { MethodName = ViewModel.MethodName };
                info.Summary = ViewModel.Summary;
                info.Remarks = ViewModel.Remark;
                info.Author = GlobalSettings.UserInfo.UserName ?? string.Empty;

                info.WriteToVS();
                this.Close();               
            }
            catch (Exception ex)
            {
                MDSOutPaneWindow.MDSTool.WriteLine(string.Empty);
                MDSOutPaneWindow.MDSTool.WriteLine("插入查询方法异常：" + ex.Message);
                if (ex.StackTrace != null)
                {
                    MDSOutPaneWindow.MDSTool.WriteLine(ex.StackTrace);
                }
                MDSOutPaneWindow.MDSTool.Activate();
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
